package test;



import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Solution {

    public static void main(String[] args) {
        String ss = "aaaaaaaaaaaaaaaaaaaaaaaa";
        int maxLength = 0;
        String result = "";

        int inputLen = ss.length()/2 + 1;
        StringBuilder builder = new StringBuilder();
        builder.append(".?");
        for(int l = inputLen; l >= 1; l--){
            builder.insert(0, "(.?)");
            builder.append("\\");
            builder.append(l);
        }

        Pattern pattern = Pattern.compile(builder.toString());
        Matcher matcher;

        for(int i = 0; i < ss.length(); i++){
            String sub = ss.substring(i, ss.length());
            matcher = pattern.matcher(sub);
            while(matcher.find() && matcher.group().length() > maxLength){
                maxLength = matcher.group().length();
                result = matcher.group();
            }
        }
        System.out.println(result);
    }
}